//
//  ComplainHistoryCell.m
//  智慧小区
//
//  Created by lab603 on 15/7/6.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "ComplainHistoryCell.h"
#import "ComplainFrame.h"
#import "Complain.h"
#define cellBorder 10
@interface ComplainHistoryCell()
//类别图标
@property (nonatomic,weak)UIImageView *typeIcon;
//时间Label
@property (nonatomic,weak)UILabel *timeLabel;
//投诉建议文字
@property (nonatomic,weak)UILabel *complainDetail;
//投诉状态图
@property (nonatomic,weak)UIImageView *statusIcon;
//业主对物业满意程度
@property (nonatomic,weak)UIImageView *ownerIcon;
//物业对投诉的认可度
@property (nonatomic,weak)UIImageView *propertyIcon;
//提醒按钮
@property (nonatomic,weak)UIButton *remindBtn;
@end
@implementation ComplainHistoryCell
+ (instancetype)cellWthTableView:(UITableView *)tableView{
    static NSString *ID = @"complainCell";
    ComplainHistoryCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell = [[ComplainHistoryCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;

}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //点击背景
        self.selectedBackgroundView = [[UIView alloc] init];
        //时间Label
        UILabel *timeLabel = [[UILabel alloc] init];
        timeLabel.textColor = [UIColor grayColor];
        timeLabel.backgroundColor = [UIColor clearColor];
        timeLabel.font = [UIFont systemFontOfSize:13.0];
        [self.contentView addSubview:timeLabel];
        self.timeLabel = timeLabel;
        //类别头像
        UIImageView *typeIcon = [[UIImageView alloc] init];
        [self.contentView addSubview:typeIcon];
        self.typeIcon = typeIcon;
        //投诉情况
        UILabel *complainDetail = [[UILabel alloc] init];
        complainDetail.textColor = [UIColor grayColor];
        complainDetail.backgroundColor = [UIColor clearColor];
        complainDetail.font = [UIFont systemFontOfSize:13.0];
        complainDetail.numberOfLines = 1;
        [self.contentView addSubview:complainDetail];
        self.complainDetail = complainDetail;
        //投诉状态图
        UIImageView *statusIcon = [[UIImageView alloc] init];
        statusIcon.image = [UIImage imageNamed:@"statusIcon_normol"];
        [self.contentView addSubview:statusIcon];
        self.statusIcon = statusIcon;
        //业主对物业满意程度
        UIImageView *ownerIcon = [[UIImageView alloc] init];
        ownerIcon.image = [UIImage imageNamed:@"ownerIcon"];
        ownerIcon.hidden = YES;
        [self.contentView addSubview:ownerIcon];
        self.ownerIcon = ownerIcon;
        //物业对投诉的认可度
        UIImageView *propertyIcon = [[UIImageView alloc] init];
        propertyIcon.image = [UIImage imageNamed:@"propertyIcon"];
        propertyIcon.hidden = YES;
        [self.contentView addSubview:propertyIcon];
        self.propertyIcon = propertyIcon;

        //提醒按钮
        UIButton *remindBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [remindBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [remindBtn setTitle:@"提醒处理" forState:UIControlStateNormal];
        [remindBtn setBackgroundColor:APP_THEME_COLOR];
        remindBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [remindBtn.layer setCornerRadius:CORNER_RADIUS_5];
        remindBtn.clipsToBounds = YES;
        [remindBtn addTarget:self action:@selector(remind) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview: remindBtn];
        self.remindBtn = remindBtn;

    }
    return self;
}
/**
 *  提醒处理
 */
- (void)remind{
    if (self.tapRemindBtnBlock) {
        self.tapRemindBtnBlock();
    }
}
- (void)setComplainF:(ComplainFrame *)complainF{
    _complainF = complainF;
    Complain *complain = complainF.complain;
    //为cell的控件设置Frame
    self.typeIcon.frame = complainF.typeIconF;
    self.timeLabel.frame = complainF.timeLabelF;
    self.complainDetail.frame = complainF.complainDetailF;
    self.statusIcon.frame = complainF.statusIconF;
    self.ownerIcon.frame = complainF.ownerIconF;
    self.propertyIcon.frame = complainF.propertyIconF;
    self.remindBtn.frame = complainF.remindBtnF;
    //为cell的控件赋值
    self.typeIcon.image = [UIImage imageNamed:@"service"];
    NSString *imageString = @"";
    switch ([complain.type intValue]) {
        case 1:{
            imageString = @"service";
        }
            break;
        case 2:{
            imageString = @"huanjing";
        }
            break;
        case 3:{
            imageString = @"zhixu";
        }
            break;
        case 4:{
            imageString = @"shoufei";
        }
            break;
        case 5:{
            imageString = @"meIcon";
        }
            break;
        case 6:{
            imageString = @"qita";
        }
            break;
        default:
            break;
    }
    self.typeIcon.image = [UIImage imageNamed:imageString];
    self.timeLabel.text = complain.lastEditTime;
    self.complainDetail.text = complain.texts;
    if (complain.status==0) {
        self.statusIcon.image = [UIImage imageNamed:@"statusIcon_normol"];
        self.ownerIcon.hidden = YES;
        self.propertyIcon.hidden = YES;
        self.remindBtn.hidden = NO;
    }else if (complain.status==1){
        self.statusIcon.image = [UIImage imageNamed:@"statusIcon_complete"];
        self.ownerIcon.hidden = NO;
        self.propertyIcon.hidden = NO;
        self.remindBtn.hidden = YES;
    }
}
- (void)setFrame:(CGRect)frame
{
    frame.origin.y += cellBorder;
    frame.size.height -= cellBorder;
    [super setFrame:frame];
}
@end
